(Annoor) 24 : 5
إِلَّا الَّذِينَ تَابُوا مِنْ بَعْدِ ذَٰلِكَ وَأَصْلَحُوا فَإِنَّ اللَّهَ غَفُورٌ رَحِيمٌ
Except for those who repented thereafter and reform; then indeed, Allah is the Forgiving and Merciful.
As per verses 39: 54-55 there are two conditions specified for getting forgiveness (1) To turn towards the Lord with soul and submit wholly to Him before death happens (2) To follow the Best Book Adhikr—before death happens unexpectedly. See explanation 2: 186 and 4: 145-146.